home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / dsp / 56ktools / a5611.tz / a5611 / examples / flange.a56 < prev    next >
Text File  |  1992-08-11  |  3KB  |  156 lines

  1. ;***************************************************************
  2. ;
  3. ;    Stereo Flange for the DSP56001 processor
  4. ;    Developed by Quinn Jensen (jensenq@npd.novell.com)
  5. ;
  6. ;***************************************************************
  7. include 'tdsg.basic.a56'
  8.  
  9. dot
  10.     org    x:$20
  11.  
  12. ; Sample rate              32.5500 kc         
  13. ; Delay time (1-12)         6.0000 ms         
  14. ; Depth (1-10)             10.0000
  15. ; Speed (1-10)              1.0000
  16. ; Regen (1-10)              9.0000
  17. ; max depth +/-             6.0000 ms         
  18. ; min delay                 1.0000 ms         
  19. ; max delay                12.0000 ms         
  20. ; 1/2 cycle period          4.5100 s          
  21. ; samples per 1/2 cyc  146800.5000
  22. ; time delta/samp           0.0817 us         
  23. ; offset samp/samp          0.0027
  24.   doff_i equ                               -33
  25.   ddeltaf equ                     0.0026607539
  26.   dspeed_i equ                          146800
  27.   dregen equ                      0.8888888889
  28.  
  29. delay    equ    $2000
  30. dmax    equ    4096        ;125 ms
  31. doff    dc    doff_i        ;current delay distance
  32.     org    y:doff
  33.     dc    0
  34.  
  35.     org    x:doff+1
  36. ddelta    dc    0        ;
  37.     org    y:ddelta
  38.     dc    ddeltaf
  39.  
  40.     org    x:ddelta+1
  41.  
  42. dspeed    dc    dspeed_i
  43. dtoggle    dc    0        ;
  44. delayout
  45.     dc    0
  46.  
  47.     org    y:$0
  48.  
  49.     org    p:dot        ;go back to P-space
  50. ;
  51. ; non-interrupt code
  52. ;
  53.  
  54. hf_init
  55.     move    #delay,r1            ;delay line input
  56.      movec    #dmax-1,m1            ;
  57.     move    #doff_i,n1            ;distance to output
  58.     rts
  59.  
  60. ;
  61. ; fs = 32.552083 kHz
  62. ;
  63.  
  64. hf_comp
  65.     jsr    <saveregs
  66. ;
  67. ;    output and input mix
  68. ;
  69.     clr    a    #.4375,x1        ;clr a, get input scale
  70.     clr    b    #.5,y1            ;clr b, get output scaler
  71.  
  72.     move        x:<delayout,y0        ;get delay out
  73.  
  74.     move        #.70,x0            ;do regen term
  75.     macr    x0,y0,a
  76.     macr    x0,y0,a
  77.  
  78.     move        #.75,x0
  79.  
  80.     macr    y0,x0,b    x:<in_l,x0        ;b = .5 * delay, x0=in_l
  81.     macr    x0,y1,b        b,y0           ;b += .5 * in_l, y0=b
  82.     macr    x0,x1,a b,x:<out_l        ;a += x1 * in_l, L = b
  83.     move            y0,b        ;b = -y0
  84.     neg    b    x:<in_r,x0        ;x0 = in_r
  85.     macr    x0,y1,b                ;b += .5 * in_r
  86.     macr    x0,x1,a    b,x:<out_r        ;R = b, a += x1 * in_r
  87. ;
  88. ;    delay line in
  89. ;
  90.     move        a,x:(r1)+
  91. ;
  92. ;    delay line length modulation
  93. ;
  94.     move        l:<doff,a        ;a = current offset
  95.     move        l:<ddelta,x        ;x = current delta
  96.     add    x,a
  97.     move        a,l:<doff        ;new offset = a + x
  98.     move        a1,n1
  99.  
  100.     move        x1,b            ;save delta for later use
  101.  
  102. ; smoothly transition between delay-line offsets by
  103. ; interpolating the current sample with the previous or next
  104. ; one depending on whether the delay is currently getting longer or
  105. ; shorter.  Otherwise, an obnoxious click results when the offset snaps
  106. ; to the next integral value.
  107.  
  108.     move            y:<doff,a    ;compute |frac(doff)|
  109.     lsr    a    #$800000,x0
  110.     or    x0,a    #.5,x1
  111.     move        a1,x0
  112.     mpy    -x0,x1,a
  113.     tst    b        a,y0        ;y0 = 0.5 * |frac(doff)|
  114.     jpl    shorter                ;on positive delta, the
  115.                         ;delay is shortening
  116.  
  117.     move        (r1)-            ;get previous sample
  118.     move        x:(r1+n1),x0
  119.     mpy    y0,x0,a    #.5,b            ;scale
  120.     sub    y0,b    (r1)+            ;compute scale for cur sample
  121.     move            b,y0
  122.     move        x:(r1+n1),x0        ;get cur sample
  123.     mac    x0,y0,a                ;scale and sum
  124.     jmp    endpan
  125.  
  126. shorter
  127.     move        x:(r1+n1),x0        ;get cur sample
  128.     mpy    y0,x0,a    #.5,b            ;scale
  129.     sub    y0,b    (r1)+            ;compute scale for next sample
  130.     move            b,y0
  131.     move        x:(r1+n1),x0        ;get next sample
  132.     mac    x0,y0,a    (r1)-            ;scale and sum
  133. endpan
  134.     move        a,x:<delayout        ;store resulting output
  135.  
  136. ; update the triangle wave modulation
  137.  
  138.     move        x:<dtoggle,a        ;decrement toggle count
  139.     move        #>1,x0
  140.     sub    x0,a
  141.     move        a,x:<dtoggle
  142.     jgt    notogg                ;time to toggle?
  143.     move        x:<dspeed,x0        ;yes, negate delta and reset
  144.     move        l:<ddelta,a
  145.     neg    a    x0,x:<dtoggle
  146.     move        a,l:<ddelta
  147. notogg
  148. bypass
  149.     jsr    <restregs
  150.     rts
  151.  
  152.     end
  153.